package com.samoiloff.util.data {
	/**
	 * @author dngr
	 * created 23.09.2011
	 */
	public class CharacterDirection {
		
		public static const UP		:int = 1;
		public static const UP_RIGHT:int = 2;
		public static const RIGHT	:int = 3;
		public static const DN_RIGHT:int = 4;
		public static const DN		:int = 5;
		public static const DN_LEFT	:int = 6;
		public static const LEFT	:int = 7;
		public static const UP_LEFT	:int = 8;
		
		public static function getLength(dx:Number, dy:Number):Number {
			return Math.sqrt(dx*dx + dy*dy);
		}
		
		public static  function getDirection(dx:Number, dy:Number):int {
			var angle : Number = Math.atan2(dx, dy);
			angle = angle * 180 / Math.PI;
			trace("CharacterDirection.getDirection (dx, dy ) : " +dx + ":" + dy + ":" + Math.round(angle));
			if (angle < 0) {
				angle = 360 + angle;
			}
			if (angle > 360) {
				angle = angle - 360;
			}


			trace("CharacterDirection.getDirection (dx, dy ) : " +dx + ":" + dy + ":" + Math.round(angle));


			if (angle >= 0 && angle < 45) return RIGHT;
			if (angle >= 45 && angle < 90) return UP_RIGHT;
			if (angle >= 90 && angle < 135) return UP;
			if (angle >= 135 && angle < 180) return UP_LEFT;
			if (angle >= 180 && angle < 225) return LEFT;
			if (angle >= 225 && angle < 270) return DN_LEFT;
			if (angle >= 270 && angle < 315) return DN;
			if (angle >= 315 && angle < 360) return DN_RIGHT;
			
//			if (angle >= 157.5) return LEFT;
//			if (angle >= 112.5) return DN_LEFT;
//			if (angle >= 67.5) return DN;
//			if (angle >= 22.5) return DN_RIGHT;
//			if (angle >= -22.5) return RIGHT;
//			if (angle >= -67.5) return UP_RIGHT;
//			if (angle >= -112.5) return UP;
//			if (angle >= -157.5) return UP_LEFT;
			return LEFT;
		}
	
		
	}
}
